<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 首页接口
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     */
    public function index()
    {

        $articleModel = Model('app\common\model\ZuowenSpider');
        $data = $articleModel->where(['ai_is_use'=>1])->order('weigh desc')->limit(50)->select();
        $result = [];
        if(!empty($data)){
            foreach($data as $k=>$v){
                $temp = [
                  'show_title' =>$v['title'],
                    'title' =>"写一篇关于".$v['title']."的".$v['nianji'].$v['xuexiao']."的作文，字数要求".$v['zishu']."字",
                    'tag' =>$v['zishu'].",".$v['nianji'].",".$v['xuexiao'],
                ];
                $result[] = $temp;
                $articleModel->where(['id'=>$v['id']])->update(['ai_is_use'=>2]);
            }
        }

        $this->success('请求成功',$result);
    }


    public function bhw(){
//        $post = file_get_contents("php://input");
        $content  = $_POST['content'];
        $title = $_POST['title'];
        $summary = $_POST['summary'];
        $type = $_POST['type'];
//        $para1 = $this->request->param('content',0);
        file_put_contents('1.txt',$content);
        $typeArr = [
          'jiyu' => 30,
            'ganyan' => 31,
            'zhufu' => 32,
            'shuxin' => 33,
        ];

        $saveData['category_pid'] = 29;
        $saveData['category_id'] = $typeArr[$type];
        $saveData['title'] = $title;
        $saveData['summary'] = $summary;
        $saveData['add_time'] = time();

        $articleModel = Model('app\common\model\Article');
        $id = $articleModel->insertGetId($saveData);
        $saveContentData['aid'] = $id;
        $saveContentData['content'] = $content;
        $articleContentModel = Model('app\common\model\ArticleContent');
//            print_r($saveContentData);
        $rs = $articleContentModel->insertGetId($saveContentData);
//        print_r(json_decode($para1,true));
        //更新首页和列表页缓存
        \think\Console::call('cachemanage', ['updatecache']);
    }
}
